package com.wanfajie.smsdistribute.ui.template_editor

import android.graphics.Color
import android.text.TextPaint
import android.text.style.ClickableSpan
import android.text.style.UpdateAppearance
import android.view.View

open class PlaceholderSpan(
        val textColor: Int? = null,
        val bgColor: Int = Color.TRANSPARENT,
        val isDrawUnderline: Boolean = false
): ClickableSpan(), UpdateAppearance {

    companion object {
        private var sIdCounter: Int = 0
    }

    /**
     * the unique ID for this span.
     */
    val id: Int = sIdCounter++

    open fun onSpanClick(view: View, span: PlaceholderSpan, text: String, pos: Int) = Unit

    override fun onClick(widget: View?) {}

    final override fun updateDrawState(tp: TextPaint?) {
        tp?.let {
            tp.color = textColor ?: tp.linkColor
            tp.isUnderlineText = isDrawUnderline
            tp.bgColor = bgColor
        }
    }
}
